var vue=new Vue({
   el:'#cqr',
   data:{
       courseName:'',
       teacher:'',
       credit:'',
   } ,
    methods:{
       addCourse:function (courseId) {
           if(vue.courseName.trim().length>12||vue.courseName.trim()==''){
               alert("课程名称不能大于12个字符！且不能为空！");
               return;
           }
           if(vue.teacher.trim().length>12||vue.teacher.trim()==''){
               alert("教师名称不能大于12个字符！且不能为空！");
               return;
           }
           if(vue.credit.trim().length>4){
               alert("学分超过表示范围！");
               return;
           }
           var reg = /^[0-9]+.?[0-9]*$/;
           if(!reg.test(vue.credit.trim())||vue.credit.trim()==''){
               alert("学分只能为数字！且不能为空！");
               return;
           }
           var data={
               courseName:vue.courseName,
               teacher:vue.teacher,
               credit:vue.credit
           }
           $.ajax({
               url:'service/addCourseService.jsp',
               data:data,
               type:'POST',
               dataType:'JSON',
               success:function (msg) {
                   window.location.reload()
                   alert(msg.message);
               }
           });
       },
        deleteCourse:function (courseId) {
            $.ajax({
                url:'service/deleteCourseService.jsp',
                data:{
                    courseId:courseId
                },
                type:'POST',
                dataType:'JSON',
                success:function (msg) {
                    window.location.reload()
                    alert(msg.message);
                }
            });
       },
    }
});